<template>
	<!-- 竞争对手 -->
	<div>
		<FormPanel
			ref="FormPanel"
			:list="initForm"
			:cols="2"
			:formType="formType"
			:labelWidth="150"
			:isSubmitBtn="false"
			@formChange="formChangeHandle"
			class="mtop"
		/>
	</div>
</template>
<script>
	import { dictionary } from '@/utils/dictMixin';
	export default {
		mixins: [dictionary],
		model:{
			prop:'pdata',
			event:'click'
		},
		props: {
			pdata: {
				type: Object,
				default: () => ({})
			},
			formType:{
				type: String,
				required:true
			}
		},
		data() {
			return {
				initForm: this.initFormFun(),
			};
		},
		methods: {
			//初始化数据
			init() {
				this.initForm.forEach(x => {
					if(x.fieldName === 'uploadFileList'){
						let fileList = this.pdata.allForm[x.fieldName];
						if(Array.isArray(fileList)){
							fileList.forEach(item => {item.name = item.fileName;item.url = item.fileId});
						}
						x.initialValue = fileList;
					}else{
						x.initialValue = this.pdata.allForm[x.fieldName];
					}
				});
			},
			formChangeHandle(val) {
				this.pdata.allForm = Object.assign(this.pdata.allForm,val);
				//传递数据到父组件里
				this.$emit('click', this.pdata);
				//触发外部的事件，以标志着本表单已经准备完毕
				this.$emit('formchange', this.pdata);
			},
			saveDialog(){
				this.$refs.FormPanel.SUBMIT_FORM();
			},
			//搜索数据
			initFormFun() {
				return [
					{
						type: 'INPUT',
						label: '竞品产品',
						fieldName: 'competingProduct',
						initialValue: '',
						placeholder:'',
						maxlength:100,
						rules:[
							{ required: true, message: "必填", trigger: "blur"},
							{ min: 0, max: 100, message: '长度在 0 到 100 个字符', trigger: 'blur' }
						],
					},
					{
						type: 'INPUT_NUMBER',
						label: '竞品价格',
						fieldName: 'competingPrice',
						initialValue: undefined,
						placeholder:'',
						precision: 2,
						max:9999999999,
						min:0,
						rules:[
							{ required: true, message: "必填", trigger: "blur"},
							{ required: true, message: "必填", trigger: "change"}
						],
					},
					{
						type: 'TEXT_AREA',
						label: '竞品商务政策和服务',
						fieldName: 'competingPolicy',
						selfCols:2,
						rows: 2,
						initialValue: '',
						placeholder:'',
						maxlength:500,
						rules:[
							{ min: 0, max: 500, message: '长度在 0 到 500 个字符', trigger: 'blur' }
						],
					},
					{
						type: 'TEXT_AREA',
						label: '竞品优劣势分析',
						fieldName: 'competingAnalyse',
						selfCols:2,
						rows: 2,
						initialValue: '',
						placeholder:'',
						maxlength:500,
						rules:[
							{ min: 0, max: 500, message: '长度在 0 到 500 个字符', trigger: 'blur' }
						],
					},
				{
					type: 'UPLOAD_FILE',
					label: '附件',
					fieldName: 'uploadFileList',
					selfCols:2,
					// disabled: this.isShow || (!this.isDep && !this.isMinister && !this.isChiefInspector),
					upload: {
						actionUrl: '/api/file/oss/upload', //上传的地址
						// fixedSize: [300, 500], //剪裁尺寸
						// isCalcHeight: false,
						min:1/1024,
						max:30 * 1024,//kb
						limit: 99, //上传数量
						fileTypes:[
							'jpg','jpeg','png','gif','bmp','webp',
							'doc','docx','xls','xlsx','ppt','pptx','txt','pdf',
							'rar','zip',
						],
					},
					initialValue: '',
					placeholder:'',
				}

				];
			}
		}
	};
</script>